package com.socodethis.spaceex;

import java.util.ArrayList;
import java.util.Random;

public class RegionGeneratorClass {
	private ArrayList <dungeonGenerator> maps;
	private ArrayList <dungeonConnect> edges;
	private Random random = new Random(System.nanoTime());
	private int indexStart;
	//The type defines the area that the region represents
	RegionGeneratorClass(int size, int type, int indexStart){
		int homeBase = 17;
		/*Region Types
		 * 0 - Village
		 * 1 - Castle
		 * 2 - Field
		 * 3 - Forest
		 */
		this.indexStart = indexStart;
		int[] dungeonList;
		switch(type){
			case 0:dungeonList = new int[3];dungeonList[0] = 4;dungeonList[1] = 14;dungeonList[2] = 15;break;
			//Dungeons 9 and 10 will always be the first and last dungeons respectively
			case 1:dungeonList = new int[3];dungeonList[0] = 2;dungeonList[1] = 8;dungeonList[2] = 0;break;
			case 2:dungeonList = new int[2];dungeonList[0] = 5;dungeonList[1] = 6;break;
			case 3:dungeonList = new int[2];dungeonList[0] = 3;dungeonList[1] = 1;break;
			case 4:dungeonList = new int[4];dungeonList[0] = 7;dungeonList[1] = 11;dungeonList[2] = 12;dungeonList[3] = 13;break;
			default:dungeonList = new int[1];dungeonList[0] = 8;break;
		}
		maps = new ArrayList <dungeonGenerator>();
		edges = new ArrayList <dungeonConnect>();
		int dungeonType;
		if(indexStart == 0){maps.add(new dungeonGenerator(0,homeBase));}
		while(maps.size()<size){
			dungeonType = dungeonList[random.nextInt( dungeonList.length )];
			if(type != 1){
				maps.add(new dungeonGenerator(maps.size()+indexStart,dungeonType));
			}else{
				if(maps.size() == 0 || (maps.size() == 1 && indexStart == 0)){
					maps.add(new dungeonGenerator(maps.size()+indexStart,9));
				}else if(maps.size() == size-1){
					maps.add(new dungeonGenerator(maps.size()+indexStart,10));
				}else{
					maps.add(new dungeonGenerator(maps.size()+indexStart,dungeonType));
				}
			}
		}
		if(maps.size() > 1){
			for(int j = 0; j < size-1;j++){
				//System.out.println("No: " + j + " Size: " + size + " Type:" + maps.get(j).getDungeonType());
				edges.add(new dungeonConnect(
				//               Entrance in j                                    Exit in j+1
				new simpleNode(j+indexStart,maps.get(j).createExit(true)),new simpleNode(j+1+indexStart,maps.get(j+1).createExit(false))
				));
			}
		}
	}
	public int getIStart(){
		return indexStart;
	}
	public int getMapSize(){
		return maps.size();
	}
	public int getEdgesSize(){
		return maps.size();
	}
	public ArrayList <dungeonGenerator> getMaps(){
		return maps;
	}
	public ArrayList <dungeonConnect> getEdges(){
		return edges;
	}
}
